package rad.framework.trace;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.event.PostDeleteEvent;
import org.hibernate.event.PostDeleteEventListener;
import org.hibernate.event.PostInsertEvent;
import org.hibernate.event.PostInsertEventListener;
import org.hibernate.event.PostUpdateEvent;
import org.hibernate.event.PostUpdateEventListener;

public class TraceListener implements PostDeleteEventListener,
		PostInsertEventListener, PostUpdateEventListener {
	private static final long serialVersionUID = 1L;

	private Log logger;

	public void onPostDelete(PostDeleteEvent event) {
		logger = LogFactory.getLog(event.getEntity().getClass());
		logger.debug(ToStringBuilder.reflectionToString(event,
				ToStringStyle.MULTI_LINE_STYLE));
	}

	public void onPostInsert(PostInsertEvent event) {
		logger = LogFactory.getLog(event.getEntity().getClass());
		logger.debug(ToStringBuilder.reflectionToString(event,
				ToStringStyle.MULTI_LINE_STYLE));
	}

	public void onPostUpdate(PostUpdateEvent event) {
		logger = LogFactory.getLog(event.getEntity().getClass());
		logger.debug(ToStringBuilder.reflectionToString(event,
				ToStringStyle.MULTI_LINE_STYLE));
	}
}
